package com.jimikongjian.service.dao.impl;

import com.jimikongjian.dao.IUnreadComment;
import com.jimikongjian.models.UnreadComment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by fuxiuyang on 17/3/4.
 */
@Service("iUnreadCommentImpl")
public class IUnreadCommentImpl implements IUnreadComment {

    @Autowired
//    @Qualifier("unreadCommentMapper")
    private IUnreadComment iUnreadComment;


    /**
     * 通过自身的id号，获取某一确定的未读消息的所有信息
     *
     * @param id
     * @return List<UnreadComment>
     */
    public List<UnreadComment> getUnreadCommentListById(int id) {
        if (id > 0){
            return iUnreadComment.getUnreadCommentListById(id);
        }
        return null;
    }

    /**
     * 通过自身的id号，获取某一确定的未读消息的所有信息
     *
     * @param id
     * @return UnreadComment
     */
    public UnreadComment getUnreadCommentById(int id) {
        if (id > 0){
            List<UnreadComment> unreadCommentList = getUnreadCommentListById(id);
            if (unreadCommentList.size() > 0){
                return unreadCommentList.get(0);
            }
        }
        return null;
    }

    /**
     * 通过用户的id，获取用户所有的未读消息
     *
     * @param userId
     * @return List<UnreadComment>
     */
    public List<UnreadComment> getUnreadCommentListByUserId(int userId, int start, int length) {
        if (userId > 0 && start >= 0 && length > 0){
            return iUnreadComment.getUnreadCommentListByUserId(userId, start, length);
        }
        return null;
    }

    /**
     * 查询表格中是否含有该未读评论
     *
     * @param userId
     * @param articleId
     * @return List<UnreadComment>
     */
    public List<UnreadComment> hasUnreadComment(int userId, int articleId) {
        if (userId > 0 && articleId > 0){
            return iUnreadComment.hasUnreadComment(userId, articleId);
        }
        return null;
    }

    /**
     * 创建一条未读消息
     *
     * @param unreadComment
     */
    public void insertUnreadComment(UnreadComment unreadComment) {
        if (unreadComment.getUserId() > 0
                && unreadComment.getArticleId() > 0
                && unreadComment.getArticleTitle() != ""
                && unreadComment.getUserId() > 0){
            iUnreadComment.insertUnreadComment(unreadComment);
        }
    }

    /**
     * 更新一条未读消息，通过id号
     *
     * @param id
     * @param unreadCount
     */
    public void updateUnreadCommentById(int id, int unreadCount) {
        if (id > 0 && unreadCount > 0){
            iUnreadComment.updateUnreadCommentById(id, unreadCount);
        }
    }

    /**
     * 更新一体未读消息，通过文章的id号
     *
     * @param articleId
     */
    public void updateUnreadCommentByArticleId(int articleId) {
        if (articleId > 0){
            iUnreadComment.updateUnreadCommentByArticleId(articleId);
        }
    }

    /**
     * 删除一条未读消息
     *
     * @param unreadComment
     */
    public void deleteUnreadComment(UnreadComment unreadComment) {
        if (unreadComment.getId() > 0){
            iUnreadComment.deleteUnreadComment(unreadComment);
        }
    }
}
